﻿namespace Services
{
    public interface IMapping<TEntity, TModel, TFilterModel>
         where TEntity : BaseEntity, new()
         where TModel : BaseModel
         where TFilterModel : BaseFilterModel
    {
        TModel Entity2Model(TEntity entity);
        TEntity Model2Entity(TModel model);
        List<TModel> Entity2Model(IEnumerable<TEntity> entities);
        List<TEntity> Model2Entity(IEnumerable<TModel> models);
        Expressionable<TEntity> FilterModel2Where(TFilterModel filterModel);
    }

    public abstract class BaseMapping<TEntity, TModel, TFilterModel> : IMapping<TEntity, TModel, TFilterModel>
        where TEntity : BaseEntity, new()
        where TModel : BaseModel
        where TFilterModel : BaseFilterModel
    {
        #region Ioc
        public readonly ICurrentUser _currentUser;
        public BaseMapping(ICurrentUser currentUser)
        {
            _currentUser = currentUser;
        }
        #endregion

        public abstract TModel Entity2Model(TEntity entity);

        public abstract TEntity Model2Entity(TModel model);

        public abstract List<TModel> Entity2Model(IEnumerable<TEntity> entities);

        public abstract List<TEntity> Model2Entity(IEnumerable<TModel> models);

        public virtual Expressionable<TEntity> FilterModel2Where(TFilterModel filterModel)
        {
            return Expressionable.Create<TEntity>();
        }
    }
}
